<style>
    .BloodSpiderGongNengQu_function-card {
        border: 1px solid #e6e6e6;
        border-radius: 5px;
        padding: 15px;
        margin-bottom: 20px;
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    }

    .BloodSpiderGongNengQu_function-header {
        font-size: 16px;
        font-weight: bold;
        margin-bottom: 15px;
        padding-bottom: 10px;
        border-bottom: 1px solid #e6e6e6;
    }

    .BloodSpiderGongNengQu_copy-content {
        background: #f8f8f8;
        padding: 15px;
        border-radius: 5px;
        margin: 15px 0;
        white-space: pre-wrap;
        word-wrap: break-word;
        font-family: 'Courier New', monospace;
    }
</style>

<!-- 订单详情模态框容器 -->
<div id="BloodSpiderGongNengQu_ModalContainer" style="display: none;">
    <div id="BloodSpiderGongNengQu_OrderDetailContent" class="BloodSpiderGongNengQu_copy-content">
        <!-- 订单信息将动态填充在此处 -->
    </div>
    <div style="text-align: right; margin-top: 10px;">
        <button class="layui-btn layui-btn-warm" id="BloodSpiderGongNengQu_CopyBtn">复制订单信息</button>
    </div>
</div>
<script>
    /**
 * 显示订单详情模态框
 */
    function showOrderDetailModal() {
        // 使用Layui的layer.open方法显示模态框
        layer.open({
            type: 1,
            title: '订单详情',
            area: ['600px', 'auto'],
            content: window.BS_Layui_$('#BloodSpiderGongNengQu_ModalContainer'),
            btn: [],
            success: function (layero, index) {
                // 复制按钮事件
                window.BS_Layui_$('#BloodSpiderGongNengQu_CopyBtn').on('click', function () {
                    var textToCopy = window.BS_Layui_$('#BloodSpiderGongNengQu_OrderDetailContent').text();

                    // 创建临时textarea元素进行复制
                    var textarea = document.createElement('textarea');
                    textarea.value = textToCopy;
                    textarea.style.position = 'fixed';
                    textarea.style.left = '-999999px';
                    textarea.style.top = '-999999px';
                    document.body.appendChild(textarea);
                    textarea.focus();
                    textarea.select();

                    try {
                        document.execCommand('copy');
                        layer.msg('复制成功', { icon: 1 });
                    } catch (err) {
                        layer.msg('复制失败，请手动复制', { icon: 2 });
                    } finally {
                        document.body.removeChild(textarea);
                    }
                });
            },
            end: function () {
                // 模态框关闭后的清理工作
                window.BS_Layui_$('#BloodSpiderGongNengQu_CopyBtn').off('click');
            }
        });
    }

    /**
 * 检查订单是否已被取消
 * 如果所有关键字段值均为null，则判定该订单已被取消
 * @param {Object} orderData - 订单数据对象
 * @returns {boolean} - 订单是否已被取消
 */
    function isAllFieldsNull(orderData) {
        var fields = [
            orderData.Title,
            orderData.Game,
            orderData.Zone,
            orderData.Actor,
            orderData.GameAcc,
            orderData.GamePass,
            orderData.GameMobile,
            orderData.LeaveTime
        ];

        // 检查所有字段是否都为null或空
        return fields.every(function (field) {
            return field === null || field === undefined || field === '';
        });
    }
    function formatOrderInfo(orderData) {
        var infoLines = [
            '代练项目：' + (orderData.Title || ''),
            '游戏区：' + (orderData.Game || ''),
            '平台服：' + (orderData.Zone || ''),
            '角色名：' + (orderData.Actor || ''),
            '号主账号: ' + (orderData.GameAcc || ''),
            '号主密码：' + (orderData.GamePass || ''),
            '号主手机：' + (orderData.GameMobile || ''),
            '代练时间：' + (orderData.LeaveTime || '')
        ];

        return infoLines.join('\n');
    }
    function getOrderDetail(dailiantongOrderId) {
        // 获取用户输入的订单ID
        var orderId = dailiantongOrderId;
        console.log(orderId);

        // 验证订单ID是否为空
        if (!orderId) {
            layer.msg('请输入订单ID', { icon: 2 });
            return;
        }

          // 调用获取订单详情接口
                axios.get('/api/dailiantong/get_order_detail/', {
                    params: {
                        order_id: orderId
                    },
                     BS_ShowLoading: true
                })
                    .then(function (response) {

                        // 检查响应状态
                        if (response.data && response.data.code === 0 && response.data.data) {
                            var orderData = response.data.data;

                            // 检查所有关键字段是否为null
                            var isOrderCanceled = isAllFieldsNull(orderData);

                            if (isOrderCanceled) {
                                // 订单已被取消
                                layer.alert('该订单已被取消', { icon: 0 });
                            } else {
                                // 格式化订单信息
                                var formattedOrderInfo = formatOrderInfo(orderData);


                                // 填充订单信息到模态框内容容器
                                window.BS_Layui_$('#BloodSpiderGongNengQu_OrderDetailContent').text(formattedOrderInfo);

                                // 显示模态框
                                showOrderDetailModal();
                            }
                        } else {
                            layer.msg('获取订单详情失败：' + (response.data ? response.data.message : '未知错误'), { icon: 2 });
                        }
                    })
                    .catch(function (error) {
                        // 显示错误信息
                        console.error('获取订单详情出错：', error);
                        layer.msg('获取订单详情时发生网络错误', { icon: 2 });
                    });
           


    }

</script>